Retry of methods based on exception type and method type

ABSTRACT

A method, apparatus, system, and signal-bearing medium that, in an embodiment, determine whether a method that attempted to use a connection to a resource is retryable based on an exception type and a method type specified in configuration data. If the method is retryable, a rollback operation is issued to the resource, a new connection to the resource is attempted, and the method is retried on the new connection. If the method is not retryable, an exception is sent to a client that requested the method. In an embodiment, the method has an associated number of maximum retries and a time period to wait between retries. In this way, clients are relieved of the burden of recovering from the failure of connections to resources.

FIELD

An embodiment of the invention generally relates to computers. In particular, an embodiment of the invention generally relates to an automatic retry of a method to a resource based on a type of the exception and a type of the method.

BACKGROUND

The development of the EDVAC computer system of 1948 is often cited as the beginning of the computer era. Since that time, computer systems have evolved into extremely sophisticated devices, and computer systems may be found in many different settings. Computer systems typically include a combination of hardware, such as semiconductors and circuit boards, and software, also known as computer programs. As advances in semiconductor processing and computer architecture push the performance of the computer hardware higher, more sophisticated and complex computer software has evolved to take advantage of the higher performance of the hardware, resulting in computer systems today that are much more powerful than just a few years ago.

Years ago, computers were isolated devices that did not communicate with each other. But, today computers are often connected in networks, such as the Internet or World Wide Web, and a user at one computer, often called a client, may wish to access information at multiple other computers, often called servers, via a network. Accessing and using information, e.g. databases or other resources, from multiple computers is often called distributed computing.

Although databases are usually reliable, if a database becomes unreachable for some reason, the existing connections to that database will not function. A database can become unreachable if, for example, the database server is shut down, connections to the database are manually dropped, or the network connection is down. In these cases, any accesses to the database will result in a database driver, which controls access to the database, throwing an exception, which is eventually propagated back to the requesting client as part of an exception chain, which may be lengthy. If the client code wants to attempt to retry the operation to the resource before returning, the client must then interrogate the exception chain to determine the root cause of the error, issue a rollback request for the transaction that encountered the error, open a new connection, and start a new transaction using the new connection.

This error recovery processing is burdensome and difficult for the client. Without a better way to handle failure of database connections, clients will continue to suffer from burdensome error recovery processing. Although the aforementioned problems have been described in the context of unreachable databases, they may occur for any type of errors or exceptions.

SUMMARY

A method, apparatus, system, and signal-bearing medium are provided that, in an embodiment, determine whether a method that attempted to use a connection to a resource is retryable based on an exception type and a method type specified in configuration data. If the method is retryable, a rollback operation is issued to the resource, a new connection to the resource is attempted, and the method is retried on the new connection. If the method is not retryable, an exception is sent to a client that requested the method. In an embodiment, the method has an associated number of maximum retries and a time period to wait between retries. In this way, clients are relieved of the burden of recovering from the failure of connections to resources.

BRIEF DESCRIPTION OF THE DRAWING

FIG. 1 depicts a block diagram of an example system for implementing an embodiment of the invention.

FIG. 2 depicts a block diagram of an example data structure for configuration data, according to an embodiment of the invention.

FIG. 3 depicts a flowchart of example processing for accessing a resource, according to an embodiment of the invention.

FIG. 4 depicts a flowchart of example processing for handling retries of methods to the resource, according to an embodiment of the invention.

DETAILED DESCRIPTION

In an embodiment, a container determines whether a method that attempted to use a connection to a resource and encountered is retryable. The container makes the determination based on configuration data that specifies methods and exception types that are retryable. An example of an exception that may be retryable is a stale, and a connection is stale if the resource is unreachable, the server that contains the resource is down, a network that connects the container to the server is down, a connection to the network is down, or an orphan timeout amount has elapsed. If the method is retryable, a rollback operation is issued to the resource, a new connection to the resource is attempted, and the method is retried on the new connection. If the method is not retryable, an exception is sent to the client that requested the method. In an embodiment, the method has an associated number of maximum retries and a time period to wait between retries.

Referring to the Drawing, wherein like numbers denote like parts throughout the several views, FIG. 1 depicts a high-level block diagram representation of a computer system 100 connected to a client 132 and a server 134 via a network 130, according to an embodiment of the present invention. The major components of the computer system 100 include one or more processors 101, a main memory 102, a terminal interface 111, a storage interface 112, an I/O (Input/Output) device interface 113, and communications/network interfaces 114, all of which are coupled for inter-component communication via a memory bus 103, an I/O bus 104, and an I/O bus interface unit 105.

The computer system 100 contains one or more general-purpose programmable central processing units (CPUs) 101A, 101B, 101C, and 101D, herein generically referred to as the processor 101. In an embodiment, the computer system 100 contains multiple processors typical of a relatively large system; however, in another embodiment the computer system 100 may alternatively be a single CPU system. Each processor 101 executes instructions stored in the main memory 102 and may include one or more levels of on-board cache.

The main memory 102 is a random-access semiconductor memory for storing data and programs. The main memory 102 is conceptually a single monolithic entity, but in other embodiments the main memory 102 is a more complex arrangement, such as a hierarchy of caches and other memory devices. For example, memory may exist in multiple levels of caches, and these caches may be further divided by function, so that one cache holds instructions while another holds non-instruction data, which is used by the processor or processors. Memory may be further distributed and associated with different CPUs or sets of CPUs, as is known in any of various so-called non-uniform memory access (NUMA) computer architectures.

The memory 102 includes a container 150 and a resource driver 152. Although the container 150 and the resource driver 152 are illustrated as being contained within the memory 102 in the computer system 100, in other embodiments some or all of them may be on different computer systems and may be accessed remotely, e.g., via the network 130. The computer system 100 may use virtual addressing mechanisms that allow the programs of the computer system 100 to behave as if they only have access to a large, single storage entity instead of access to multiple, smaller storage entities. Thus, while the container 150 and the resource driver 152 are illustrated as being contained within the main memory 102, these elements are not necessarily all completely contained in the same storage device at the same time. Further, although the container 150 and the resource driver 152 are illustrated as being separate entities, in other embodiments some of them, or portions of some of them, may be packaged together.

The container 150 includes configuration data 154 and a component 156. In various embodiments, the component 156 may be a servlet, a session bean, or an entity bean, but in other embodiments any appropriate component may be used. The component 156 includes code 158 that establishes connections to resources via the resource driver 152 and determines whether an exception returned from the resource driver 152 indicates an exception that can be retried, as further described below with reference to FIGS. 3 and 4. The configuration data 154 describes the circumstances under which methods in the code 158 are to be retried, as further described below with reference to FIG. 2. In various embodiments, the resource driver 152 may be a J2EE (Java 2 Enterprise Edition) JDBC (Java Database Connectivity) driver, a J2EE JCA (Java Connector Architecture) resource adapter, or any other appropriate resource driver. The configuration data 154 may be supplied by the provider of the methods in the code 158 or from any other appropriate source.

In an embodiment, the container 150 includes instructions capable of executing on the processor 101 or statements capable of being interpreted by instructions executing on the processor 101 to perform the functions as further described below with reference to FIGS. 3 and 4. In another embodiment, the container 150 may be implemented in microcode. In another embodiment, the container 150 may be implemented in hardware via logic gates and/or other appropriate hardware techniques.

The memory bus 103 provides a data communication path for transferring data among the processor 101, the main memory 102, and the I/O bus interface unit 105. The I/O bus interface unit 105 is further coupled to the system I/O bus 104 for transferring data to and from the various I/O units. The I/O bus interface unit 105 communicates with multiple I/O interface units 111, 112, 113, and 114, which are also known as I/O processors (IOPs) or I/O adapters (IOAs), through the system I/O bus 104. The system I/O bus 104 may be, e.g., an industry standard PCI bus, or any other appropriate bus technology.

The I/O interface units support communication with a variety of storage and I/O devices. For example, the terminal interface unit 111 supports the attachment of one or more user terminals 121, 122, 123, and 124. The storage interface unit 112 supports the attachment of one or more direct access storage devices (DASD) 125, 126, and 127 (which are typically rotating magnetic disk drive storage devices, although they could alternatively be other devices, including arrays of disk drives configured to appear as a single large storage device to a host). The contents of the main memory 102 may be stored to and retrieved from the direct access storage devices 125, 126, and 127.

The I/O and other device interface 113 provides an interface to any of various other input/output devices or devices of other types. Two such devices, the printer 128 and the fax machine 129, are shown in the exemplary embodiment of FIG. 1, but in other embodiment many other such devices may exist, which may be of differing types. The network interface 114 provides one or more communications paths from the computer system 100 to other digital devices and computer systems; such paths may include, e.g., one or more networks 130.

Although the memory bus 103 is shown in FIG. 1 as a relatively simple, single bus structure providing a direct communication path among the processors 101, the main memory 102, and the I/O bus interface 105, in fact the memory bus 103 may comprise multiple different buses or communication paths, which may be arranged in any of various forms, such as point-to-point links in hierarchical, star or web configurations, multiple hierarchical buses, parallel and redundant paths, etc. Furthermore, while the I/O bus interface 105 and the I/O bus 104 are shown as single respective units, the computer system 100 may in fact contain multiple I/O bus interface units 105 and/or multiple I/O buses 104. While multiple I/O interface units are shown, which separate the system I/O bus 104 from various communications paths running to the various I/O devices, in other embodiments some or all of the I/O devices are connected directly to one or more system I/O buses.

The computer system 100 depicted in FIG. 1 has multiple attached terminals 121, 122, 123, and 124, such as might be typical of a multi-user “mainframe” computer system. Typically, in such a case the actual number of attached devices is greater than those shown in FIG. 1, although the present invention is not limited to systems of any particular size. The computer system 100 may alternatively be a single-user system, typically containing only a single user display and keyboard input, or might be a server or similar device which has little or no direct user interface, but receives requests from other computer systems (clients). In other embodiments, the computer system 100 may be implemented as a personal computer, portable computer, laptop or notebook computer, PDA (Personal Digital Assistant), tablet computer, pocket computer, telephone, pager, automobile, teleconferencing system, appliance, or any other appropriate type of electronic device.

The network 130 may be any suitable network or combination of networks and may support any appropriate protocol suitable for communication of data and/or code to/from the computer system 100. In various embodiments, the network 130 may represent a storage device or a combination of storage devices, either connected directly or indirectly to the computer system 100. In an embodiment, the network 130 may support Infiniband. In another embodiment, the network 130 may support wireless communications. In another embodiment, the network 130 may support hard-wired communications, such as a telephone line or cable. In another embodiment, the network 130 may support the Ethernet IEEE (Institute of Electrical and Electronics Engineers) 802.3x specification. In another embodiment, the network 130 may be the Internet and may support IP (Internet Protocol). In another embodiment, the network 130 may be a local area network (LAN) or a wide area network (WAN). In another embodiment, the network 130 may be a hotspot service provider network. In another embodiment, the network 130 may be an intranet. In another embodiment, the network 130 may be a GPRS (General Packet Radio Service) network. In another embodiment, the network 130 may be a FRS (Family Radio Service) network. In another embodiment, the network 130 may be any appropriate cellular data network or cell-based radio network technology. In another embodiment, the network 130 may be an IEEE 802.11B wireless network. In still another embodiment, the network 130 may be any suitable network or combination of networks. Although one network 130 is shown, in other embodiments any number (including zero) of networks (of the same or different types) may be present.

The client 132 includes an application 135, which sends requests to the container 150. The client 132 may also includes any or all of the hardware and/or software elements previously described above for the computer system 100. Although only one client 132 and one application 135 are illustrated in FIG. 1, in other embodiments any number of clients 132 and any number of applications 135 may be present. In another embodiment, the application 135 is present at the computer system 100, and the client 132 is not present, optional, or not used.

The server 134 includes a resource 136. In an embodiment, the resource 136 is a database, but in other embodiments the resource 136 may be any type of data repository. The server 134 may also include any or all of the hardware and/or software elements previously described above for the computer system 100. Although only one server 134 and one resource 136 are illustrated in FIG. 1, in other embodiments any number of servers 134 and any number of resources 136 may be present. In another embodiment, the resource 136 is present at the computer system 100, and the server 134 is not present, optional, or not used.

It should be understood that FIG. 1 is intended to depict the representative major components of the computer system 100, the network 130, the client 132, and the server 134 at a high level, that individual components may have greater complexity that represented in FIG. 1, that components other than or in addition to those shown in FIG. 1 may be present, and that the number, type, and configuration of such components may vary. Several particular examples of such additional complexity or additional variations are disclosed herein; it being understood that these are by way of example only and are not necessarily the only such variations.

The various software components illustrated in FIG. 1 and implementing various embodiments of the invention may be implemented in a number of manners, including using various computer software applications, routines, components, programs, objects, modules, data structures, etc., referred to hereinafter as “computer programs,” or simply “programs.” The computer programs typically comprise one or more instructions that are resident at various times in various memory and storage devices in the computer system 100, and that, when read and executed by one or more processors 101 in the computer system 100, cause the computer system 100 to perform the steps necessary to execute steps or elements comprising the various aspects of an embodiment of the invention.

Moreover, while embodiments of the invention have and hereinafter will be described in the context of fully functioning computer systems, the various embodiments of the invention are capable of being distributed as a program product in a variety of forms, and the invention applies equally regardless of the particular type of signal-bearing medium used to actually carry out the distribution. The programs defining the functions of this embodiment may be delivered to the computer system 100 via a variety of signal-bearing media, which include, but are not limited to:

(1) information permanently stored on a non-rewriteable storage medium, e.g., a read-only memory device attached to or within a computer system, such as a CD-ROM, DVD-R, or DVD+R;

(2) alterable information stored on a rewriteable storage medium, e.g., a hard disk drive (e.g., the DASD 125, 126, or 127), CD-RW, DVD-RW, DVD+RW, DVD-RAM, or diskette; or

(3) information conveyed by a communications medium, such as through a computer or a telephone network, e.g., the network 130, including wireless communications.

Such signal-bearing media, when carrying machine-readable instructions that direct the functions of the present invention, represent embodiments of the present invention.

Embodiments of the present invention may also be delivered as part of a service engagement with a client corporation, nonprofit organization, government entity, internal organizational structure, or the like. Aspects of these embodiments may include configuring a computer system to perform, and deploying software systems and web services that implement, some or all of the methods described herein. Aspects of these embodiments may also include analyzing the client company, creating recommendations responsive to the analysis, generating software to implement portions of the recommendations, integrating the software into existing processes and infrastructure, metering use of the methods and systems described herein, allocating expenses to users, and billing users for their use of these methods and systems.

In addition, various programs described hereinafter may be identified based upon the application for which they are implemented in a specific embodiment of the invention. But, any particular program nomenclature that follows is used merely for convenience, and thus embodiments of the invention should not be limited to use solely in any specific application identified and/or implied by such nomenclature.

The exemplary environments illustrated in FIG. 1 are not intended to limit the present invention. Indeed, other alternative hardware and/or software environments may be used without departing from the scope of the invention.

FIG. 2 depicts a block diagram of an example data structure for the configuration data 154, according to an embodiment of the invention. The configuration data 154 includes records 205 and 210, but in other embodiments any number of records with any appropriate data may be present. Each of the records 205 and 210 includes a method type field 215, an exception type field 217, a retryable field 220, a number of retires field 225, and a time field 230. In other embodiments, more or fewer fields may be present in the records 205 and 210. The method type field 215 contains identifications of container-managed transaction (CMT) methods that are executed by the code 158 as a part of transactions to the resource 136. The exception type field 217 identifies a type of error or exception that may be encountered by the method type 215. The retryable field 220 indicates whether the associated method identified in the method type field 215 is eligible to be retried if the exception type 217 is encountered by the method 215. The retries field 225 contains the maximum of number of times that the exception type 217 is to be retried. The retries field 225 is valid if the retryable field 220 indicates that the exception type 217 encountered by the methods identified in the method type field 215 is retryable. The time field 230 indicates the time to wait between retries. The time field 230 is valid if the retryable field 220 indicates that the exception type 217 encountered by the methods identified in the method type field 215 is retryable.

In the example illustrated in FIG. 2, the record 205 contains an indication of the transfer from checking to savings method in the method type field 215, an indication of a stale connection exception in the exception type field 217, an indication that the method type 215 is retryable in the retryable field 220, a number of retries of ten in the retries field 225, and a time to wait between retries of two seconds in the time field 230. In various embodiments, the connection to the resource 136 is stale when the resource 136 is unreachable, the server 134 containing the resource 136 is down, the network 130 is down, the connection to the network 130 is down, an orphan timeout amount has elapsed, multiple threads are using the same connection and one of them closes the connection. An orphan timeout occurs when a time period expires, after which the container 150 is no longer willing to keep the connection allocated because the requesting thread of the application 135 is not responding. Hence, the connection is referred to as “orphaned” because the container 150 assumes that the requesting “parent” thread has “died.”

The record 210 contains an indication of the clear buffer method in the method type field 215, an indication of a stale connection exception in the exception type field 217, an indication that the method type 215 is not retryable in the retryable field 220, a number of retries of zero in the retries field 225, and a time to wait between retries of zero seconds in the time field 230.

FIG. 3 depicts a flowchart of example processing for accessing the resource 136, according to an embodiment of the invention. Control begins at block 300. Control then continues to block 305 where the application 135 sends a request to the component 156 to connect to the resource 136. Control then continues to block 310 where the component 156 sends a request to the resource driver 152 to access the resource 136. Control then continues to block 315 where the resource driver 152 attempts to access the resource 136. Control then continues to block 320 where the resource driver 152 determines if an exception was detected while attempting to access the resource 136.

If the determination at block 320 is true, then an exception was detected while attempting to access the resource 136, so control continues to block 325 where the resource driver 152 sends the exception to the code 158. Control then continues to block 330 where the code 158 determines whether the combination of the detected exception and the method that encountered the exception has a record in the configuration data 154, such as the record 205 or 210. The code 158 makes the determination by interrogating the method type field 215 and the exception type field 217. In an embodiment, the code 158 finds the root cause of the exception by peeling down or searching through an exception chain for the source of the exception.

If the determination at block 330 is true, then the combination of the detected exception and the method that encountered the exception have an associated record in the configuration data 154, so control continues to block 335 where the container 150 determines if the method in the component 156 that encountered the exception is retryable by finding the record in the configuration data 154 for the method in the method type field 215 and checking the corresponding retryable field 220.

If the determination at bock 335 is true, then the method in the component 156 that encountered the exception is retryable, so control continues to block 340 where retries are handled, as further described below with reference to FIG. 4. Control then returns to block 320, as previously described above.

If the determination at block 335 is false, then the method in the component 156 that encountered the exception is not retryable, so control continues to block 345 where the code 158 performs normal exception processing. Control then continues to block 398 where the logic of FIG. 3 returns.

If the determination at block 330 is false, then the exception and the method do not have an associated record in the configuration data 154, so control continues to block 345 where the code 158 performs normal exception processing. Control then continues to block 398 where the logic of FIG. 3 returns.

If the determination at block 320 is false, then the resource driver 152 did not detect an exception while accessing the resource 136, so control continues to block 399 where the logic of FIG. 3 returns.

FIG. 4 depicts a flowchart of example processing for handling retries of operations to the resource 136, according to an embodiment of the invention. Control begins at block 400. Control then continues to block 405 where the container 150 determines if the number of retires already performed is less than the maximum number of retries 225 for the current method.

If the determination at block 405 is true, then the number of retries already performed is less than the maximum number of retries 225 for the current method, so control continues to block 407 where the container 150 waits for the period of time indicated in the time 230 in the record in the configuration data 154 for the current method. Control then continues to block 410 where the container 150 issues a rollback command to the resource 136 via the resource driver 152. Control then continues to block 415 where the container 150 starts a new transaction. Control then continues to block 420 where the container 150 calls the code 158 to retry the method that failed (the method that encountered the exception type 217). Control then continues to block 425 where the code 158 attempts a new connection to the resource 136 via the resource driver 152 and retries the method via the new connection. Control then continues to block 499 where the logic of FIG. 4 returns.

If the determination at block 405 is false, then the number of retries already performed is not less than the maximum number of retries 225 for the current method, so control continues to block 430 where the container 150 sends the exception to the client 132. Control then continues to block 499 where the logic of FIG. 4 returns.

In the previous detailed description of exemplary embodiments of the invention, reference was made to the accompanying drawings (where like numbers represent like elements), which form a part hereof, and in which is shown by way of illustration specific exemplary embodiments in which the invention may be practiced. These embodiments were described in sufficient detail to enable those skilled in the art to practice the invention, but other embodiments may be utilized and logical, mechanical, electrical, and other changes may be made without departing from the scope of the present invention. Different instances of the word “embodiment” as used within this specification do not necessarily refer to the same embodiment, but they may. The previous detailed description is, therefore, not to be taken in a limiting sense, and the scope of the present invention is defined only by the appended claims.

In the previous description, numerous specific details were set forth to provide a thorough understanding of the invention. But, the invention may be practiced without these specific details. In other instances, well-known circuits, structures, and techniques have not been shown in detail in order not to obscure the invention. 

1. A method comprising: detecting an exception encountered by a method using a connection; determining whether the method is retryable based on configuration data, wherein the configuration data comprises an identification of an exception type and a method type; attempting a new connection to the resource if the method is retryable; and retrying the method via the new connection if the method is retryable.
 2. The method of claim 1, wherein the determining further comprises: determining whether a number of retries is less than a maximum for the method.
 3. The method of claim 1, further comprising: sending an exception to a client that requested the method if the method is not retryable.
 4. The method of claim 1, wherein the detecting further comprises: searching an exception chain for the source of the exception.
 5. An apparatus comprising: means for detecting an exception encountered by a method using a connection; means for determining whether the method is retryable based on configuration data, wherein the configuration data comprises an identification of an exception type and a method type; means for issuing a rollback to the resource if the method is retryable; means for attempting a new connection to the resource if the method is retryable; and means for retrying the method via the new connection if the method is retryable.
 6. The apparatus of claim 5, wherein the means for determining further comprises: means for determining whether a number of retries is less than a maximum for the method.
 7. The apparatus of claim 5, further comprising: means for sending an exception to a client that requested the method if the method is not retryable.
 8. The apparatus of claim 5, wherein the exception indicates that the resource is unreachable.
 9. A signal-bearing medium encoded with instructions, wherein the instructions when executed comprise: deciding whether a connection to a resource is stale; determining whether a method that attempted to use the connection is retryable if the connection is stale based on configuration data associated with the method; issuing a rollback to the resource if the method is retryable; attempting a new connection to the resource if the method is retryable; retrying the method via the new connection if the method is retryable; and sending an exception to a client that requested the method if the method is not retryable.
 10. The signal-bearing medium of claim 9, wherein the determining further comprises: determining whether a number of retries is less than a maximum for the method.
 11. The signal-bearing medium of claim 9, wherein the connection to the resource is stale if the resource is unreachable.
 12. The signal-bearing medium of claim 9, further comprising: waiting for a time period before retrying the method.
 13. A computer system comprising: a processor; and a main memory encoded with instructions, wherein the instructions when executed on the processor comprise: deciding whether a connection to a resource is stale, determining whether a method that attempted to use the connection is retryable if the connection is stale based on configuration data associated with the method, issuing a rollback to the resource if the method is retryable, attempting a new connection to the resource if the method is retryable, retrying the method via the new connection if the method is retryable, and sending an exception to a client that requested the method if the method is not retryable.
 14. The computer system of claim 13, wherein the determining further comprises: determining whether a number of retries is less than a maximum for the method.
 15. The computer system of claim 13, wherein the connection to the resource is stale if the resource is closed.
 16. The computer system of claim 13, further comprising: waiting for a time period before retrying the method.
 17. A method for configuring a computer, comprising: configuring the computer to detect an exception encountered by a method using a connection; configuring the computer to determine whether the method is retryable based on configuration data, wherein the configuration data comprises an identification of an exception type and a method type; configuring the computer to attempt a new connection to the resource if the method is retryable; and configuring the computer to retry the method via the new connection if the method is retryable.
 18. The method of claim 17, wherein the configuring the computer to determine further comprises: configuring the computer to determine whether a number of retries is less than a maximum for the method.
 19. The method of claim 17, further comprising: configuring the computer to send an exception to a client that requested the method if the method is not retryable.
 20. The method of claim 17, wherein the configuring the computer to detect further comprises: configuring the computer to search an exception chain for the source of the exception. 